
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单管理</title>
    {include file="include/top"}
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            {if $isAdmin==true}
            {include file="include/input" class2='layui-inline' type='text' title="会员ID" name='uid' value=''}
            {include file="include/selectsearch" title="渠道" classname='supplierID' optionHtml='<?php echo isset($supplier)?$supplier:"";?>' }
            {include file="include/input" class2='layui-inline' type='text' title="油站ID" name='gasID' value=''}
            {include file="include/input" class2='layui-inline' type='text' title="渠道单号" name='supplier_no' value=''}
            {else}
            {include file="include/selectsearch" title="油站ID" classname='gasID' optionHtml='<?php echo isset($serviceOption)?$serviceOption:"";?>' }
            {/if}

            {include file="include/input" class2='layui-inline' type='text' title="订单号" name='order_no' value=''}
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="status">
                        <option value="">筛选属性</option>
                        <option value="0">添加</option>
                        <option value="1">上游预收单</option>
                        <option value="2">待支付</option>
                        <option value="3">已支付</option>
                        <option value="4">已推送</option>
                        <option value="-1">预收单失败</option>
                        <option value="-2">支付提交失败</option>
                        <option value="-3">取消支付</option>
                        <option value="-4">已退款</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">退款</label>
                <div class="layui-input-inline">
                    <select name="reOrder">
                        <option value="">筛选退款状态</option>
                        <option value="0">正常</option>
                        <option value="1">发起退款</option>
                        <option value="2">退款完成</option>
                        <option value="-1">退款拒绝</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">开始日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="startTime" id="startTime" placeholder="请填入..." autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="endTime" id="endTime" placeholder="请填入..." autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
        <table class="layui-table" lay-data="{height:0, url:'usersList', page:true, id:'idTest',toolbar: '#toolbarDemo' ,cellMinWidth: 80,limit:20}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox'}"></th>
                <th lay-data="{field:'id',  sort: true, width:80}">ID</th>
                <th lay-data="{field:'order_no'}">本地单号</th>
                <th lay-data="{field:'uid'}">用户ID</th>
                <th lay-data="{field:'addTime'}">下单时间</th>
                <th lay-data="{field:'gasID',templet:function(d){
                    return d.name+' - '+d.gasID
                }}">油站</th>
                <th lay-data="{field:'supplier',templet:function(d){
                    return d.supplier +' - ' + d.supplierID
                }}">所属渠道</th>
                <th lay-data="{field:'supplier_no'}">渠道单号</th>
                <th lay-data="{field:'oil_no'}">油号</th>
                <th lay-data="{field:'oil_gun'}">枪号</th>
                <th lay-data="{field:'amount'}">总金额</th>
                <th lay-data="{field:'sale'}">优惠</th>
                <th lay-data="{field:'payPrice'}">实付</th>
                <th lay-data="{field:'pay_no'}">付款单号</th>
                <th lay-data="{field:'volume'}">加油量</th>
                <th lay-data="{field:'reOrder',templet:function(d){
                    if(d.reOrder==1){
                        return '发起退款';
                    }else if(d.reOrder==0){
                        return '正常';
                    }else if(d.reOrder==2){
                        return '完成退款';
                    }else if(d.reOrder==3){
                        return '上游审核中';
                    }
                }}">退款</th>
                <th lay-data="{field:'status',templet:function(d){
                    if(d.status==1){
                        return '上游预收单';
                    }else if(d.status==2){
                        return '待支付';
                    }else if(d.status==3){
                        return '已支付';
                    }else if(d.status==4){
                        return '支付并推送';
                    }else if(d.status==-4){
                        return '已退款';
                    }else{
                        return '取消';
                    }
                }}">状态</th>
                <th lay-data="{align:'center', toolbar: '#barDemo',width:90}"></th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="more">操作<i
                    class="layui-icon layui-icon-down"></i></a>
        </script>
        <script type="text/html" id="toolbarDemo">
        <span id="getMsg"></span>
        </script>
    </div>
</div>
<input type='file' id='upimg' name='file' style="display: none;">
{include file="include/js"}
<script>
    var pathid=0;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table','upload','dropdown','laydate'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var pathid=0;
        var id=0;
        var selectIDS=[];
        var upload = layui.upload;
        var dropdown = layui.dropdown
        var imgType=0;
        var imgSrc='';
        var field;
        window.getMsg=function ($res){
            $("#getMsg").html($res.msg)
        }
        laydate.render({
            elem: '#startTime'
        });
        laydate.render({
            elem: '#endTime'
        });
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            field = data.field;
            //执行重载
            table.reload('idTest', {
                where: field,page:{curr:1}
            });
        });
        $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            var that = this
            if (obj.event === 'more') {
                //更多下拉菜单
                var thatData = data
                var btnArr=[{
                    title: '支付信息'
                    , id: 'payInfo'
                },{
                    title: '查询支付'
                    , id: 'pay'
                },{
                    title: '发起退单'
                    , id: 'del'
                }]
                if(data.reOrder == 1){
                    btnArr.push({title:'拒绝退单',id:"sayNo"})
                }
                dropdown.render({
                    elem: that
                    , show: true //外部事件触发即显示
                    , data:btnArr
                    , click: function (data, othis) {
                        //根据 id 做出不同操作
                        if (data.id === 'del') {
                            if(thatData.status>2){
                                layer.prompt({title:"请输入操作密码"},function (re){
                                    $.post("ordersDel?id="+thatData.id,{password:re},function (re) {
                                        layer.closeAll()
                                        layer.msg(re.msg,function (){
                                            if(re.code == 0 ){
                                                table.reload('idTest', {
                                                    where: field
                                                });
                                            }
                                        });
                                    },'json');
                                })
                            }else {
                                layer.msg("未支付订单")
                            }
                        }
                        if (data.id === 'sayNo') {
                            if(thatData.status>2){
                                layer.prompt({title:"请输入拒绝原因"},function (re){
                                    $.post("ordersDelNo?id="+thatData.id,{content:re},function (re) {
                                        layer.closeAll()
                                        layer.msg(re.msg,function (){
                                            if(re.code == 0 ){
                                                table.reload('idTest', {
                                                    where: field
                                                });
                                            }
                                        });
                                    },'json');
                                })
                            }else {
                                layer.msg("未支付订单")
                            }
                        }
                        if (data.id === 'push') {
                            if(thatData.status=='已支付'){
                                layer.confirm("是否确定手动推送渠道？",function (){
                                    $.post("push?id="+thatData.id,function (re) {
                                        layer.msg(re.msg,function (){
                                            if(re.code == 0 ){
                                                table.reload('idTest', {
                                                    where: field
                                                });
                                            }
                                        });
                                    },'json');
                                })
                            }else {
                                layer.msg("非待推送状态")
                            }
                        }else if (data.id == 'payInfo') {
                            //编辑
                           layer.open({
                               type:1,
                               content:"<div style='padding: 20px;width: 300px;'>"+thatData.payJson+"</div>",
                               area: ['80%', '80%']
                           })
                        }else if (data.id == 'fahuo') {
                            //编辑客户
                            if(thatData.status!=1){
                                layer.msg("非发货状态")
                            }
                            layer.prompt({title:"请输入快递单号"},function (re){
                                $.post("postGoodsSave?id="+thatData.id,{orderNo:re},function (re) {
                                    layer.msg(re.msg,function (){
                                        if(re.code == 0 ){
                                            table.reload('idTest', {
                                                where: field
                                            });
                                        }
                                    });
                                },'json');
                            })
                        }
                    }
                    , align: 'right' //右对齐弹出（v2.6.8 新增）
                    , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                });
            }

        });
        function delUser(){
            layer.confirm("是否删除订单？",function (re){
                $.post("orsersDel?id="+id,function (re) {
                    layer.msg(re.msg,function (){
                        if(re.code == 0 ){
                            table.reload('idTest', {
                                where: field
                            });
                        }
                    });
                },'json');
            })
        }
        function setEnd(){
            layer.confirm("是否完成订单？",function (re){
                $.post("setEnd?id="+id,function (re) {
                    layer.msg(re.msg,function (){
                        if(re.code == 0 ){
                            table.reload('idTest', {
                                where: field
                            });
                        }
                    });
                },'json');
            })
        }




    });
</script>

</body>
</html>
